package com.czk.server;

import com.czk.codec.ObjDecoder;
import com.czk.codec.ObjEncoder;
import com.czk.domain.MsgInfo;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/4/22 10:52
 */
public class MyChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        // 拿到通道
        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast(new ObjEncoder(MsgInfo.class));
        pipeline.addLast(new ObjDecoder(MsgInfo.class));
        // 加入编解码器
        pipeline.addLast(new MyChannelHandler());
    }
}
